<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">  <!-- Use Chrome Frame in IE -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="description" content="Sample photogrammetry and classification datasets both rendered with 3D Tiles.">
    <meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles">
    <title>Cesium Demo</title>
    <script type="text/javascript" src="../Sandcastle-header.js"></script>
    <script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
    <script type="text/javascript">
    require.config({
        baseUrl : '../../../Source',
        waitSeconds : 60
    });
    </script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
    @import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
    'use strict';
//Sandcastle_Begin
// An example of using a b3dm tilset to classify another b3dm tileset.
var viewer = new Cesium.Viewer('cesiumContainer');

// A normal b3dm tileset of photogrammetry
Cesium.CesiumIon.create3DTileset(1458, { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxYmJiNTAxOC1lOTg5LTQzN2EtODg1OC0zMWJjM2IxNGNlYmMiLCJpZCI6NDQsImFzc2V0cyI6WzE0NThdLCJpYXQiOjE0OTkyNjM4MjB9.1WKijRa-ILkmG6utrhDWX6rDgasjD7dZv-G5ZyCmkKg' })
    .then(function(tileset) {
        viewer.scene.primitives.add(tileset);
        viewer.zoomTo(tileset);
    })
    .otherwise(function(error) {
        console.log(error);
    });

// A b3dm tileset used to classify the photogrammetry tileset
var classificationPromise = Cesium.CesiumIon.create3DTileset(3625, {
    accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhZDI4YzA2Ny03YTIwLTQ5ZWEtODY3My1hMzU0OTJmMjEwMWQiLCJpZCI6NDQsImFzc2V0cyI6WzM2MjVdLCJpYXQiOjE1MTU1OTMxODN9.cntiWhEEBAeUb9Lq4ECpwpUuz9yZzEqOvucYopTjA5k',
    tilesetOptions: { classificationType: Cesium.ClassificationType.CESIUM_3D_TILE }
}).then(function(classification) {
    classification.style = new Cesium.Cesium3DTileStyle({
        color: 'rgba(255, 0, 0, 0.5)'
    });
    return viewer.scene.primitives.add(classification);
}).otherwise(function(error) {
    console.log(error);
});

// The same b3dm tileset used for classification, but rendered normally for comparison.
var nonClassificationPromise = Cesium.CesiumIon.create3DTileset(3625, {
    accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhZDI4YzA2Ny03YTIwLTQ5ZWEtODY3My1hMzU0OTJmMjEwMWQiLCJpZCI6NDQsImFzc2V0cyI6WzM2MjVdLCJpYXQiOjE1MTU1OTMxODN9.cntiWhEEBAeUb9Lq4ECpwpUuz9yZzEqOvucYopTjA5k',
    tilesetOptions: { show: false }
}).then(function(nonClassification) {
    nonClassification.style = new Cesium.Cesium3DTileStyle({
        color: 'rgba(255, 0, 0, 0.5)'
    });
    return viewer.scene.primitives.add(nonClassification);
}).otherwise(function(error) {
    console.log(error);
});

Cesium.when.join(classificationPromise, nonClassificationPromise).then(function(results) {
    var classification = results[0];
    var nonClassification = results[1];
    Sandcastle.addToggleButton('Show classification', true, function(checked) {
        classification.show = checked;
        nonClassification.show = !checked;
    });
});
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
    startup(Cesium);
} else if (typeof require === "function") {
    require(["Cesium"], startup);
}
</script>
</body>
</html>
